home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Games / ms-0.07 / xms / main.c < prev    next >
C/C++ Source or Header  |  1995-06-26  |  6KB  |  203 lines

  1. /* main.c - main program for MandelSpawn */
  2.  
  3. /*  
  4.     This file is part of MandelSpawn, a network Mandelbrot program.
  5.  
  6.     Copyright (C) 1990-1993 Andreas Gustafsson
  7.  
  8.     MandelSpawn is free software; you can redistribute it and/or modify
  9.     it under the terms of the GNU General Public License, version 1,
  10.     as published by the Free Software Foundation.
  11.  
  12.     MandelSpawn is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.  
  17.     You should have received a copy of the GNU General Public License,
  18.     version 1, along with this program; if not, write to the Free 
  19.     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21.  
  22. #include <stdio.h>
  23. #include <X11/Intrinsic.h>
  24. #include <X11/Shell.h>
  25. #include <X11/Xos.h>    /* just for rindex() declaration / macro */
  26. #include <X11/StringDefs.h>
  27. #ifdef MENU
  28. #include <X11/Xaw/SimpleMenu.h>
  29. #endif
  30.  
  31. #include "backward.h"    /* X11R2 backward compatibility stuff */
  32.  
  33. #include "Mama.h"
  34. #include "Ms.h"
  35.  
  36. #include "version.h"
  37.  
  38. static XrmOptionDescRec options[] = {
  39.     {"-center",         "*center_box", XrmoptionNoArg, "True" },
  40.     {"-chunk_width",     "*chunk_width", XrmoptionSepArg, NULL },
  41.     {"-chunk_height",     "*chunk_height", XrmoptionSepArg, NULL },
  42.     {"-colors",         "*colours",    XrmoptionSepArg, NULL }, 
  43.     {"-colours",     "*colours",    XrmoptionSepArg, NULL },
  44.     {"-cursor",         "*cursor",     XrmoptionSepArg, NULL },
  45.     {"-geometry",     "*ms_1.geometry", XrmoptionSepArg, NULL },
  46.     {"-iterations",     "*hues",    XrmoptionSepArg, NULL },
  47.     {"-nocenter",     "*center_box", XrmoptionNoArg, "False" },
  48.     {"-spectrum",     "*spectrum",    XrmoptionSepArg, NULL },
  49.     {"-greyscale",     "*spectrum",    XrmoptionNoArg, "white-black" },
  50.     {"-grayscale",     "*spectrum",    XrmoptionNoArg, "white-black" },
  51.     {"-x",         "*ms_1*center_x", XrmoptionSepArg, NULL },
  52.     {"-y",         "*ms_1*center_y", XrmoptionSepArg, NULL },
  53.     {"-range",         "*ms_1*range",    XrmoptionSepArg, NULL },
  54.     {"-julia",         "*ms_1*julia",    XrmoptionNoArg, "True" },
  55.     {"-cx",         "*ms_1*c_x",    XrmoptionSepArg, NULL },
  56.     {"-cy",         "*ms_1*c_y",    XrmoptionSepArg, NULL },
  57.     {"-bw",         "*bw",        XrmoptionNoArg, "True" },
  58.     {"-wrap",         "*wrap",    XrmoptionNoArg, "True" },
  59.     {"-nowrap",         "*wrap",    XrmoptionNoArg, "False" },
  60.     {"-interior",     "*interior",    XrmoptionNoArg, "True" },
  61.     {"-sony",         "*sony_bug_workaround",
  62.                                XrmoptionNoArg, "True" },
  63.     {"-crosshair_size",     "*ms_1*crosshair_size",
  64.                                        XrmoptionSepArg, NULL },
  65.     {"-animate",     "*animate",    XrmoptionNoArg, "True" },
  66.     {"-speed",         "*animation_speed",
  67.                            XrmoptionSepArg, NULL }
  68. };
  69.  
  70.  
  71. /* Ugly global state */
  72.  
  73. XtAppContext thisApp;
  74. Display *myDisplay;
  75. int myScreenNo;
  76. Screen *myScreen;
  77.  
  78.  
  79. /* Genereate a usage message */
  80.  
  81. static void
  82. Usage(name)
  83. String name;
  84. { int i;
  85.   fprintf(stderr, "usage: %s ", name);
  86.   for(i=0; i<XtNumber(options); i++)
  87.   { printf("[%s%s]%s", options[i].option,
  88.        options[i].argKind==XrmoptionSepArg ? " ..." : "",
  89.        i==XtNumber(options)-1 ? "\n" :
  90.          i%4==3 ? "\n\t" : " ");
  91.   }
  92.   exit(1);
  93. }
  94.  
  95.  
  96. #ifdef R4
  97.  
  98. /* 
  99.   Type converter from String to Double - why on Earth isn't this in
  100.   Xt?  There is a converter from String to Float that first converts a
  101.   string to a double and then goes to the additional trouble of
  102.   truncating it into a float... but not one returning a double.  
  103. */
  104.  
  105. #define    done(type, value) \
  106.     {                            \
  107.         if (toVal->addr != NULL) {                \
  108.         if (toVal->size < sizeof(type)) {        \
  109.             toVal->size = sizeof(type);            \
  110.             return False;                \
  111.         }                        \
  112.         *(type*)(toVal->addr) = (value);        \
  113.         }                            \
  114.         else {                        \
  115.         static type static_val;                \
  116.         static_val = (value);                \
  117.         toVal->addr = (XtPointer)&static_val;        \
  118.         }                            \
  119.         toVal->size = sizeof(type);                \
  120.         return True;                    \
  121.     }
  122.  
  123.  
  124. static Boolean CvtStringToDouble(dpy, args, num_args,
  125.                  fromVal, toVal, closure_ret)
  126.      Display* dpy;
  127.      XrmValuePtr args;
  128.      Cardinal *num_args;
  129.      XrmValuePtr fromVal;
  130.      XrmValuePtr toVal;
  131.      XtPointer    *closure_ret;
  132. { double d;
  133.   double atof();
  134.   if (*num_args != 0)
  135.     XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  136.             "wrongParameters", "cvtStringToDouble", "XtToolkitError",
  137.             "String to Double conversion needs no extra arguments",
  138.             (String *) NULL, (Cardinal *) NULL);
  139.   
  140.   d = atof(fromVal->addr);
  141.   done(double, d);
  142. }
  143. #endif
  144.  
  145.  
  146. int main(argc, argv)
  147.   int argc; char *argv[];
  148. {
  149.     Widget toplevel;
  150.     MamaWidget theMama;
  151.     char *name;
  152.     Arg arglist[12];
  153.     int num_args;
  154.     Arg shell_arglist[12];
  155.     int num_shell_args;
  156.  
  157.     if (name = rindex(argv[0], '/')) name++;
  158.     else name = argv[0];
  159.  
  160.     toplevel = XtInitialize(NULL, "Ms", 
  161.                 options, XtNumber(options),
  162.                 &argc, argv);
  163.     thisApp=XtWidgetToApplicationContext(toplevel);
  164.     myDisplay=XtDisplay(toplevel);
  165.     myScreen=ScreenOfDisplay(myDisplay, myScreenNo = DefaultScreen(myDisplay));
  166.  
  167.     if (argc == 2 && !strcmp(argv[1], "-version"))
  168.       printf("MandelSpawn version %s\n", ms_version);
  169.     else
  170.       if (argc != 1)
  171.     Usage(name);
  172.  
  173. #ifdef R4
  174.     XtAppSetTypeConverter(thisApp, XtRString, XtRDouble, CvtStringToDouble,
  175.               NULL, 0, XtCacheAll, NULL);
  176. #endif
  177.  
  178.     theMama=(MamaWidget) 
  179.       XtCreateManagedWidget("mama",
  180.                 (WidgetClass) mamaWidgetClass, 
  181.                 (Widget) toplevel, 
  182.                 (ArgList) NULL, 
  183.                 0);
  184.  
  185. #ifdef MENU
  186.     XawSimpleMenuAddGlobalActions(thisApp);
  187. #endif
  188.  
  189.     /*
  190.       We supply no arguments to the shell, but the PopupAnother 
  191.       function does, so we need to pass a real buffer (not NULL)
  192.     */
  193.     num_shell_args=0;
  194.  
  195.     /* create an initial child with default settings */
  196.     num_args=0;
  197.     XtSetArg(arglist[num_args], XtNMama, theMama); num_args++;
  198.     PopupAnother(theMama, shell_arglist, num_shell_args, arglist, num_args);
  199.  
  200.     XtMainLoop();
  201.     return(0); /* keep lint happy */
  202. }
  203.